package com.qf.service;

import com.qf.dto.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author NingZhongYi
 * @Date 2020-03-11
 */
@Service
public class CartService {

    @Autowired
    private RestTemplate restTemplate;

    // 查看购物车
    public ResultBean showCart(String uuid){
        String format = String.format("http://spring-cloud-service-cart/showCart/%s", uuid);
      return restTemplate.getForObject(format,ResultBean.class);
    }

    // 添加商品到购物车
    public ResultBean addProductToCart(String uuid,Long productId,Integer count) {
        String path=String.format("http://spring-cloud-service-cart/addCart/%s/%s",productId,count);
        return restTemplate.getForObject(path,ResultBean.class);
    }

    // 清楚购物车
    public ResultBean cleanCart(String uuid) {
        String format = String.format("http://spring-cloud-service-cart/cleanCart/%s", uuid);
        return restTemplate.getForObject(format,ResultBean.class);
    }
}
